package cbfg.ssholder

import android.annotation.SuppressLint
import android.app.*
import android.content.Context
import android.content.pm.PackageManager
import android.hardware.SensorManager
import android.location.LocationManager
import android.media.AudioManager
import android.net.ConnectivityManager
import android.net.wifi.WifiManager
import android.os.PowerManager
import android.os.Vibrator
import android.os.storage.StorageManager
import android.telephony.TelephonyManager
import android.view.WindowManager
import android.view.inputmethod.InputMethodManager
import cbfg.butil.AppHolder

/**
 * 添加人：  Tom Hawk
 * 添加时间：2019/10/22 9:01
 * 功能描述：系统服务对象管理
 * <p>
 * 修改人：  Tom Hawk
 * 修改时间：2019/10/22 9:01
 * 修改内容：
 */
@SuppressLint("WifiManagerLeak")
object SysServiceHolder {
    //网络连接管理
    val connManager: ConnectivityManager by lazy { get(Context.CONNECTIVITY_SERVICE) }

    //wifi 管理
    val wifiManager: WifiManager by lazy { get(Context.WIFI_SERVICE) }

    //闹钟管理
    val alarmManager: AlarmManager by lazy { get(Context.ALARM_SERVICE) }

    //通知管理
    val notificationManager: NotificationManager by lazy { get(Context.NOTIFICATION_SERVICE) }

    //位置管理
    val locationManager: LocationManager by lazy { get(Context.LOCATION_SERVICE) }

    //振动传感器
    val vibrator: Vibrator by lazy { get(Context.VIBRATOR_SERVICE) }

    //音量管理
    val audioManager: AudioManager by lazy { get(Context.AUDIO_SERVICE) }

    //电话管理
    val telephoneManager: TelephonyManager by lazy { get(Context.TELEPHONY_SERVICE) }

    //输入法管理
    val inputMethodManager: InputMethodManager by lazy { get(Context.INPUT_METHOD_SERVICE) }

    //下载管理
    val downloadManager: DownloadManager by lazy { get(Context.DOWNLOAD_SERVICE) }

    //利用此服务可以实现对系统中的应用、联系人、SMS等进行搜索
    val searchManager: SearchManager by lazy { get(Context.SEARCH_SERVICE) }

    //电源管理
    val powerManager: PowerManager by lazy { get(Context.POWER_SERVICE) }

    //获取系统内存信息以及进程信息
    val activityManager: ActivityManager by lazy { get(Context.ACTIVITY_SERVICE) }

    //窗口管理
    val windowManager: WindowManager by lazy { get(Context.WINDOW_SERVICE) }

    //屏幕保护
    val keyguardManager: KeyguardManager by lazy { get(Context.KEYGUARD_SERVICE) }

    //传感器管理
    val sensorManager: SensorManager by lazy { get(Context.SENSOR_SERVICE) }

    //存储管理
    val storageManager: StorageManager by lazy { get(Context.STORAGE_SERVICE) }

    //安装包管理
    val pkgManager: PackageManager by lazy { AppHolder.appContext().packageManager }

    @Suppress("UNCHECKED_CAST")
    internal fun <T> get(name: String): T {
        return AppHolder.appContext().getSystemService(name) as T
    }
}